﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using System.Data;

public partial class views_ShoppingCart : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {

        if (this.IsPostBack) return;
        load_cart();
    }

    
    public void load_cart()
    {
        products gio = (products)Session["Cart"];
        if (gio != null)
        {
            this.rpt_giohang.DataSource = gio.Data;
            this.rpt_giohang.DataBind();
        }
    }
    protected void rpt_giohang_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        if (e.CommandName == "UpdateQuantity")
        {
            TextBox _txtQuantity = (TextBox)e.Item.FindControl("txtQuantity");
            products gio = (products)Session["GioHang"];

            if (gio != null && _txtQuantity != null)
            {
                int _quantity = 0;
                int.TryParse(_txtQuantity.Text, out _quantity);
                gio.UpdateQuantity(e.CommandArgument.ToString(), _quantity);
                load_cart();
            }
        }
    }
}